﻿Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.OleDb

Module publicM
    Public arrString(6) As String                           '各道大题的相关说明
    Public arrStringDart(40, 7) As String                   '0元素为题干，5为时间，6为正确答案，7为答题者选择的答案
    Public arrStringMultiple(20, 8) As String               '0元素为题干，6为时间，7为正确答案，8为答题者选择的答案
    Public arrStringTorF(20, 6) As String                   '0元素为题干，4为时间，5为正确答案，6为答题者选择的答案
    Public arrComprehensive(5, 5, 6) As String                 '二维0元素为大题题干，1为ID,2为时间
    'Public arrCSun(5, 6) As String                          '0为小题干，5为正确答案，6为答题者选择的答案
    Public AB As Int16 = 0                                  '0为A套题，1为B套题

    Public tempButton As Button = New Button()              '当前题按钮
    Public tempRB As RadioButton = New RadioButton()       '当前RadioButton
    Public tempCK As CheckBox = New CheckBox()              '当前CheckBox
    Public tempNo As Int16 = 0                              '当前题号
    Public tempNoJ As Int16 = 0                             '综合大题题号
    Public ZZZ As Double = 0                                '最终得分


#Region "初始化数据函数"
    Public Function getInitE(ByVal tType As Int16) As Boolean

        arrString(1) = "一、单选题：单项选择共 【40】 题，每题限 【60】 秒内完成；每题由1个题干、4个备选项组成，其中有1个为正确或最符合题意的选项。选择正确每题得1分，错选、不选，不得分。"
        arrString(2) = "二、多选题：多项选择共 【20】 题，每题限 【120】 秒内完成；每题由1个题干、5个备选项组成，其中有2~4个为正确或符合题意的选项。全部选择正确每题得2分；少选且选择正确，每个选项得0.5分；错选、不选，本题不得分。"
        arrString(3) = "三、判断题：判断共 【20】 题，每题限 【30】 秒内完成；每题为一个陈述句。判断题，判断正确得1分；不判断不得分；判断错误扣1分，最多扣至本科目判断题总分为0分。"
        arrString(4) = "一、多选题：多项选择共 【15】 题，每题限 【120】 秒内完成；每题由1个题干、5个备选项组成，其中有2~4个为正确或符合题意的选项。全部选择正确每题得2分；少选且选择正确，每个选项得0.5分；错选、不选，本题不得分。"
        arrString(5) = "二、判断题：判断共 【20】 题，每题限 【30】 秒内完成；每题为一个陈述句。判断题，判断正确得1分；不判断不得分；判断错误扣1分，最多扣至本科目判断题总分为0分。"
        arrString(6) = "三、综合分析题：综合分析题共 【5】 大题，每大题各 【5】 小题，每大题限 【600】 秒内完成；每大题由案情和5个小题组成。每个小题由1个题干、4个备选项组成，有1~4个为正确或符合题意的选项。每小题全部正确得2分；少选且选择正确每个选项得0.5分；错选、不选，本小题不得分。"



        AB = tType

        '获取各种题

        Dim ranKs As Random = New Random()
        Dim tempKs As Int16 = 0

        tempKs = Int(ranKs.Next(3)) + 1


        Dim cdo As New clsDataOpt("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Data\ks" & tempKs & ".mdb")
        Dim txtMsg As String = ""
        Dim daSet As New DataSet()

        Dim r As Single
        Randomize()
        r = Rnd()
        Dim strTemp As String = ""

        Try
            If tType = 0 Then
                '获取制度与政策的考核题
                'Get Dart
                strTemp = "select top 40 * from tblDart order by rnd( " & r & " -dart_id)"
                Randomize()
                r = Rnd()
                daSet = Nothing
                daSet = cdo.ExecuteSQL(strTemp, txtMsg)

                For i As Int16 = 1 To daSet.Tables(0).Rows.Count
                    arrStringDart(i, 0) = daSet.Tables(0).Rows(i - 1).Item(1)   'question
                    arrStringDart(i, 1) = daSet.Tables(0).Rows(i - 1).Item(2)   'A
                    arrStringDart(i, 2) = daSet.Tables(0).Rows(i - 1).Item(3)   'B
                    arrStringDart(i, 3) = daSet.Tables(0).Rows(i - 1).Item(4)   'C
                    arrStringDart(i, 4) = daSet.Tables(0).Rows(i - 1).Item(5)   'D
                    arrStringDart(i, 5) = "60"                                  'Time   
                    arrStringDart(i, 6) = daSet.Tables(0).Rows(i - 1).Item(6)   'right answer
                    arrStringDart(i, 7) = ""                                    'about answer
                Next

                'Get Multiple
                Randomize()
                r = Rnd()
                strTemp = "select top 20 * from tblMultiple order by rnd( " & r & " -Multiple_id)"

                daSet = Nothing
                daSet = cdo.ExecuteSQL(strTemp, txtMsg)

                For i As Int16 = 1 To daSet.Tables(0).Rows.Count
                    arrStringMultiple(i, 0) = daSet.Tables(0).Rows(i - 1).Item(1)   'question
                    arrStringMultiple(i, 1) = daSet.Tables(0).Rows(i - 1).Item(2)   'A
                    arrStringMultiple(i, 2) = daSet.Tables(0).Rows(i - 1).Item(3)   'B
                    arrStringMultiple(i, 3) = daSet.Tables(0).Rows(i - 1).Item(4)   'C
                    arrStringMultiple(i, 4) = daSet.Tables(0).Rows(i - 1).Item(5)   'D
                    arrStringMultiple(i, 5) = daSet.Tables(0).Rows(i - 1).Item(6)   'E
                    arrStringMultiple(i, 6) = "120"                                 'Time
                    arrStringMultiple(i, 7) = daSet.Tables(0).Rows(i - 1).Item(7)   'right answer
                    arrStringMultiple(i, 8) = ""                                    'about answer
                Next


                'Get TorF
                Randomize()
                r = Rnd()
                strTemp = "select top 20 * from tblTorF order by rnd( " & r & " -TorF_id)"

                daSet = Nothing
                daSet = cdo.ExecuteSQL(strTemp, txtMsg)

                For i As Int16 = 1 To daSet.Tables(0).Rows.Count
                    arrStringTorF(i, 0) = daSet.Tables(0).Rows(i - 1).Item(1)   'question
                    arrStringTorF(i, 1) = "对"
                    arrStringTorF(i, 2) = "错"
                    arrStringTorF(i, 3) = "放弃"
                    arrStringTorF(i, 4) = "30"                                  'Time
                    arrStringTorF(i, 5) = daSet.Tables(0).Rows(i - 1).Item(2)   'right answer
                    arrStringTorF(i, 6) = ""                                    'about answer
                Next

                Return True
            Else
                '获取实务与案例的考核题
                'Get Multiple
                Randomize()
                r = Rnd()
                strTemp = "select top 15 * from tblMultipleA order by rnd( " & r & " -Multiple_id)"
                'strTemp = "select top 15 * from tblMultiple order by rnd( " & r & " -Multiple_id)"

                daSet = Nothing
                daSet = cdo.ExecuteSQL(strTemp, txtMsg)

                For i As Int16 = 1 To daSet.Tables(0).Rows.Count
                    arrStringMultiple(i, 0) = daSet.Tables(0).Rows(i - 1).Item(1)   'question
                    arrStringMultiple(i, 1) = daSet.Tables(0).Rows(i - 1).Item(2)   'A
                    arrStringMultiple(i, 2) = daSet.Tables(0).Rows(i - 1).Item(3)   'B
                    arrStringMultiple(i, 3) = daSet.Tables(0).Rows(i - 1).Item(4)   'C
                    arrStringMultiple(i, 4) = daSet.Tables(0).Rows(i - 1).Item(5)   'D
                    arrStringMultiple(i, 5) = daSet.Tables(0).Rows(i - 1).Item(6)   'E
                    arrStringMultiple(i, 6) = "120"                                 'Time
                    arrStringMultiple(i, 7) = daSet.Tables(0).Rows(i - 1).Item(7)   'right answer
                    arrStringMultiple(i, 8) = ""                                    'about answer
                Next


                'Get TorF
                Randomize()
                r = Rnd()
                strTemp = "select top 20 * from tblTorFA order by rnd( " & r & " -TorF_id)"
                'strTemp = "select top 20 * from tblTorF order by rnd( " & r & " -TorF_id)"

                daSet = Nothing
                daSet = cdo.ExecuteSQL(strTemp, txtMsg)

                For i As Int16 = 1 To daSet.Tables(0).Rows.Count
                    arrStringTorF(i, 0) = daSet.Tables(0).Rows(i - 1).Item(1)   'question
                    arrStringTorF(i, 1) = "对"
                    arrStringTorF(i, 2) = "错"
                    arrStringTorF(i, 3) = "放弃"
                    arrStringTorF(i, 4) = "30"                                  'Time
                    arrStringTorF(i, 5) = daSet.Tables(0).Rows(i - 1).Item(2)   'right answer
                    arrStringTorF(i, 6) = ""                                    'about answer
                Next

                'Get Comprehensive
                Randomize()
                r = Rnd()
                strTemp = "select top 5 * from tblComprehensive order by rnd( " & r & " -comprehensive_id)"

                daSet = Nothing
                daSet = cdo.ExecuteSQL(strTemp, txtMsg)

                For i As Int16 = 1 To daSet.Tables(0).Rows.Count

                    arrComprehensive(i, 0, 0) = daSet.Tables(0).Rows(i - 1).Item(1)    'question
                    arrComprehensive(i, 0, 1) = daSet.Tables(0).Rows(i - 1).Item(0)    'id
                    arrComprehensive(i, 0, 2) = "600"                                  'time
                Next
                '对应5道小题
                For i As Int16 = 1 To 5
                    Randomize()
                    r = Rnd()
                    strTemp = "select cSun_id,cSun_title,cSun_A,cSun_B,cSun_C,cSun_D,cSun_answer from tblCSun where C_id=" & arrComprehensive(i, 0, 1) & " order by rnd(" & r & "-cSun_id)"
                    daSet = Nothing
                    daSet = cdo.ExecuteSQL(strTemp, txtMsg)

                    For j As Int16 = 1 To daSet.Tables(0).Rows.Count

                        arrComprehensive(i, j, 0) = daSet.Tables(0).Rows(j - 1).Item(1)         'question
                        arrComprehensive(i, j, 1) = daSet.Tables(0).Rows(j - 1).Item(2)         'A
                        arrComprehensive(i, j, 2) = daSet.Tables(0).Rows(j - 1).Item(3)         'B
                        arrComprehensive(i, j, 3) = daSet.Tables(0).Rows(j - 1).Item(4)         'C
                        arrComprehensive(i, j, 4) = daSet.Tables(0).Rows(j - 1).Item(5)         'D
                        arrComprehensive(i, j, 5) = daSet.Tables(0).Rows(j - 1).Item(6)         'right answer
                        arrComprehensive(i, j, 6) = ""                                          'about answer
                    Next
                Next
                Return True
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
            Return False
        End Try

    End Function
#End Region


#Region "获取单项选择和判断题答案函数"
    Function getAboutAnswer(ByVal tempStr As String, ByVal tempT As String) As Int16
        Dim tempABCD As Int16 = 0
        Select Case tempT
            Case "单选题"
                Select Case tempStr
                    Case "A"
                        tempABCD = 1
                    Case "B"
                        tempABCD = 2
                    Case "C"
                        tempABCD = 3
                    Case "D"
                        tempABCD = 4
                End Select
            Case "判断题"
                Select Case tempStr
                    Case "对"
                        tempABCD = 1
                    Case "错"
                        tempABCD = 2
                    Case "放弃"
                        tempABCD = 3
                End Select
        End Select
        Return tempABCD
    End Function
#End Region


#Region "多选获取答案和判断设置函数"
    Function getMAnswer(ByVal tempStr As String, ByVal tempAnswer As Int16) As Boolean
        Dim tempABCDE As String = ""
        Select Case tempAnswer
            Case 1
                tempABCDE = "A"
            Case 2
                tempABCDE = "B"
            Case 3
                tempABCDE = "C"
            Case 4
                tempABCDE = "D"
            Case 5
                tempABCDE = "E"
        End Select

        getMAnswer = IIf(InStr(tempStr, tempABCDE) > 0, True, False)

    End Function

    Function setMAnswer(ByVal tempStr As String, ByVal tempAnswer As String) As String
        If InStr(tempStr, tempAnswer) > 0 Then
            Return tempStr
        Else
            tempStr = tempStr & tempAnswer
            tempStr = getMAS(tempStr)
        End If
        Return tempStr
    End Function

    Function setMA(ByVal tempStr As String, ByVal tempAnswer As String) As String
        If InStr(tempStr, tempAnswer) > 0 Then
            'MsgBox(InStr(tempStr, tempAnswer))
            tempStr = Mid(tempStr, 1, InStr(tempStr, tempAnswer) - 1) & Mid(tempStr, InStr(tempStr, tempAnswer) + 1, Len(tempStr))
            Return tempStr
        Else
            Return tempStr
        End If
    End Function

    Function getMAS(ByVal tempStr As String) As String          '多选排序
        Dim i As Int16, j As Int16, S() As String, t As String
        ReDim S(Len(Trim(tempStr)))
        getMAS = ""
        For i = LBound(S) To UBound(S)
            S(i) = Mid(Trim(tempStr), i + 1, 1)
        Next

        For i = 0 To UBound(S)
            For j = i + 1 To UBound(S)
                If S(j) < S(i) Then t = S(i) : S(i) = S(j) : S(j) = t
            Next
            getMAS = getMAS & S(i)
            getMAS = Trim(getMAS)
        Next
    End Function
#End Region


End Module
